﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core.DataContract;
using WordNet.Core;
using WordNet.Core.ElementContracts;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestDataLineNoun:UnitTestBase
    {
        const string NOUN_DATA_LINE = @"02064081 05 n 03 dog 0 domestic_dog 0 Canis_familiaris 0 022 @ 02063374 n 0000 #m 02063873 n 0000 #m 07886597 n 0000 ~ 01306302 n 0000 ~ 02064724 n 0000 ~ 02064853 n 0000 ~ 02065264 n 0000 ~ 02065366 n 0000 ~ 02067096 n 0000 ~ 02083377 n 0000 ~ 02089732 n 0000 ~ 02090197 n 0000 ~ 02090349 n 0000 ~ 02090520 n 0000 ~ 02090668 n 0000 ~ 02090886 n 0000 ~ 02091012 n 0000 ~ 02091875 n 0000 ~ 02092204 n 0000 ~ 02092713 n 0000 ~ 02093356 n 0000 %p 02137696 n 0000 | a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds; ""the dog barked all night"" ";
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }
       
        [TestMethod]
        public void CanParseNounData()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);

        }

        [TestMethod] 
        public void CanParseNounDataOffset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(int.Parse("02064081"), synset.Offset);

        }

        [TestMethod]
        public void CanParseNounDataLexFile()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(5, synset.LexicalFile.Number);
            Assert.AreEqual(POS.NOUN, synset.LexicalFile.PartOfSpeech);
            Assert.AreEqual(LexFile.NOUN_ANIMAL.Name, synset.LexicalFile.Name);

            Assert.AreEqual(LexFile.GetLexicalFile(5), synset.LexicalFile);

        }

        [TestMethod]
        public void CanParseNounDataPOS()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(POS.NOUN, synset.PartOfSpeech);

        }

        [TestMethod]
        public void CanParseNounDataNumberOfWords()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);

            Assert.AreEqual(Convert.ToInt32("03", 16), synset.GetWords().Count);

        }

        [TestMethod]
        public void CanParseNounDataWords()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);

            string expectedValue = "dog";
            Assert.AreEqual(expectedValue, synset.GetWord(1).Lemma);
            Assert.AreEqual(0, synset.GetWord(1).LexicalID);

            expectedValue = "domestic_dog";
            Assert.AreEqual(expectedValue, synset.GetWord(2).Lemma);
            Assert.AreEqual(0, synset.GetWord(2).LexicalID);

            expectedValue = "Canis_familiaris";
            Assert.AreEqual(expectedValue, synset.GetWord(3).Lemma);
            Assert.AreEqual(0, synset.GetWord(3).LexicalID);
        }

        [TestMethod]
        public void CanParseNounDataNumberOfSynsetPointers()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);

            Assert.AreEqual(Convert.ToInt32("022"), synset.GetRelatedSynsets().Count);

        }

        [TestMethod]
        public void CanParseNounDataSynsetPointers()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);

            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.HYPERNYM));
            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.HOLONYM_MEMBER));
            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.HYPONYM));
            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.MERONYM_PART));

            Assert.IsFalse(synset.GetRelatedMap().ContainsKey(Pointer.MERONYM_SUBSTANCE));

        }

        [TestMethod]
        public void CanParseNounDataHypernymSynset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(1, synset.GetRelatedSynsets(Pointer.HYPERNYM).Count);
            Assert.AreEqual(int.Parse("02063374"), synset.GetRelatedSynsets(Pointer.HYPERNYM)[0].Offset);


        }

        [TestMethod]
        public void CanParseNounDataHolonymMemberSynset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(2, synset.GetRelatedSynsets(Pointer.HOLONYM_MEMBER).Count);
            Assert.AreEqual(int.Parse("02063873"), synset.GetRelatedSynsets(Pointer.HOLONYM_MEMBER)[0].Offset);
            Assert.AreEqual(int.Parse("07886597"), synset.GetRelatedSynsets(Pointer.HOLONYM_MEMBER)[1].Offset);

        }

        [TestMethod]
        public void CanParseNounDataHyponymSynset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(18, synset.GetRelatedSynsets(Pointer.HYPONYM).Count);
            Assert.AreEqual(int.Parse("01306302"), synset.GetRelatedSynsets(Pointer.HYPONYM)[0].Offset);
            Assert.AreEqual(int.Parse("02064724"), synset.GetRelatedSynsets(Pointer.HYPONYM)[1].Offset);
            Assert.AreEqual(int.Parse("02093356"), synset.GetRelatedSynsets(Pointer.HYPONYM)[17].Offset);
        }

        [TestMethod]
        public void CanParseNounDataMenonyPartSynset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(1, synset.GetRelatedSynsets(Pointer.MERONYM_PART).Count);
            Assert.AreEqual(int.Parse("02137696"), synset.GetRelatedSynsets(Pointer.MERONYM_PART)[0].Offset);

        }

        [TestMethod]
        public void CanParseNounDataGloss()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(NOUN_DATA_LINE);
            Assert.IsNotNull(synset);
            Assert.IsTrue(NOUN_DATA_LINE.Trim().EndsWith(synset.Gloss));

        }
    }
}
